using Godot;
using System;

public partial class NItem : Area2D
{
	public static string CUR_SEL_ITEM = "CUR_SEL_ITEM";
	[Export] public CItem mItem;
	TextureRect mImg;
	TextureRect mImgBig;
	// Called when the node enters the scene tree for the first time.
	public override void _Ready()
	{
		mImgBig = GetNode<TextureRect>("TextureRectBig");
		mImg = GetNode<TextureRect>("TextureRect");

		if (mItem != null && !string.IsNullOrEmpty(mItem.mImg))
			mImg.Texture = ResourceLoader.Load<Texture2D>(mItem.mImg);
		if (mImgBig != null && !string.IsNullOrEmpty(mItem.mImg))
			mImgBig.Texture = ResourceLoader.Load<Texture2D>(mItem.mImg);

		adjustPos();
	}

	// Called every frame. 'delta' is the elapsed time since the previous frame.
	public override void _Process(double delta)
	{
		if (GetParentOrNull<NWeaponInventoryPanel>() != null)
		{
			mImg.Visible = false;
			mImgBig.Visible = true;
			return;
		}
		if (GetParentOrNull<NInventoryPanel>() != null)
		{
			mImg.Visible = true;
			mImgBig.Visible = false;
			return;
		}
	}

	public void adjustPos()
	{
		NInventoryPanel p = GetParentOrNull<NInventoryPanel>();
		if (p != null)
		{
			Position = p.Size / 2;
		}
	}

}
